package com.action.tree.bean;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
//import javax.servlet.http.HttpServletRequest;
import com.dao.DataOperations;
import com.dbtools.Dispose;
//import com.util.SessionUtils;
import com.exception.SelectException;
import com.action.tree.TreeInfo;
import com.action.tree.TreeOperation;

public class OrgTree extends DataOperations implements TreeOperation{
	public OrgTree() {
		super();
	}
	public OrgTree(Connection connection) {
		super(connection);
	}
    
	public List select(Object obj) throws SelectException{
		List list=new ArrayList();
		StringBuffer sql = new StringBuffer();
		//HttpServletRequest request=(HttpServletRequest)obj;
		//String orgid = SessionUtils.getManagOrgId(request);
		sql.append("SELECT ORGID,CODE,NAME,PARENTID,ISDEL,SEQ FROM( ");
    	sql.append("SELECT  ORGID, CODE, NAME, PARENTID, ISDEL, LEVEL SEQ ");
    	sql.append("FROM  T_S_ORG  CONNECT BY PRIOR ORGID = PARENTID ");
    	sql.append("START WITH PARENTID = '****'  ORDER SIBLINGS BY  ORGID ASC)  WHERE ISDEL = '0' AND SEQ < '4'");
/*		sql.append("select distinct orgid, code, name, parentid ");
		sql.append(" from t_s_org where isdel = '0' ");
		sql.append(" START WITH orgid = any('"+orgid.replaceAll(",", "','")+"') CONNECT BY PRIOR orgid=parentid order by orgid"); 		
*/		ResultSet rest=null;
		try {
		   rest = super.executeQuery(sql.toString());
		   while(rest.next()){
			 TreeInfo info=new TreeInfo();
			 info.setId(rest.getString("ORGID"));
			 info.setParentId(rest.getString("PARENTID"));
			 info.setText("(" + rest.getString("CODE") + ")"+ rest.getString("NAME"));
			 list.add(info);
			}
		} catch (SQLException e) {
			throw new SelectException(e.getMessage());
		} finally {
			Dispose.dispose(rest);
		}
		return list;
	}
	public boolean delete(Object obj) {
		return false;
	}
	public boolean insert(Object obj) {
		return false;
	}
	public boolean update(Object obj) {
		return false;
	}

}
